# 定义登录网站操作函数
from common.globals import *
import cv2
from typing import Type, TypeVar
from definition.ProInfo import UserInfoClass

from settings import *
from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC



def createuser(UserInobj):
    print(UserInobj.username, UserInobj.password)




def login_site(driver, UserInobj):
    # driver是：webdriver对象

    # 打开登录页面
    driver.get(url)
    # 输入用户名
    driver.find_element(By.ID, '').send_keys(UserInobj.username)
    # 输入密码
    driver.find_element(By.ID, "password").send_keys(UserInobj.password)
    # 识别验证码
    identify_captcha(driver)
    # 点击登录按钮
    driver.find_element("loginBtn").click()

# 定义识别验证码函数
def identify_captcha(driver):
    # 识别验证码
    captcha_img = driver.find_element_by_xpath("//img[@class='captcha-img']")
    captcha_src = captcha_img.get_attribute("src")
    # 下载验证码图片
    response = requests.get(captcha_src)
    with open("captcha.jpg", "wb") as f:
        f.write(response.content)
    # 识别验证码
    captcha_code = input("请输入验证码：")
    # 输入验证码